<?php

namespace CMBUBank\UBank;

/**
 * 招行-云直联
 */

use CMBUBank\UBank\Info\TransManager\Payee;
use CMBUBank\UBank\Request\Account\AccountHandleAccountInfoRequest;
use CMBUBank\UBank\Request\Account\AccountHandleAccountListRequest;
use CMBUBank\UBank\Request\Account\AccountHandleBusinessInquiryRequest;
use CMBUBank\UBank\Request\Account\AccountPDFApplyRequest;
use CMBUBank\UBank\Request\Account\AccountPDFDownloadRequest;
use CMBUBank\UBank\Request\Account\AccountTradeListQueryRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerCloseSubunitRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerCreateSubunitRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitControlRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitDecontrolRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitHistoryTradeQueryRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitInterTransferRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitPaymentRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitPDFCreateRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitPDFDownloadRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitQueryInfoRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitRefundRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitTodayTradeRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitWhiteAddRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitWhiteDeleteRequest;
use CMBUBank\UBank\Request\TransManager\TransManagerSubunitWhiteListRequest;
use CMBUBank\UBank\Request\TransManager\TransManageSubunitListRequest;
use CMBUBank\UBank\Response\Account\AccountHandleAccountInfoResponse;
use CMBUBank\UBank\Response\Account\AccountHandleAccountListResponse;
use CMBUBank\UBank\Response\Account\AccountHandleBusinessInquiryResponse;
use CMBUBank\UBank\Response\Account\AccountPDFApplyResponse;
use CMBUBank\UBank\Response\Account\AccountPDFDownloadResponse;
use CMBUBank\UBank\Response\Account\AccountTradeListQueryResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerCloseSubunitResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerCreateSubunitResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitControlResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitDecontrolResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitHistoryTradeQueryResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitInterTransferResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitListResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitPaymentResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitPDFCreateResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitPDFDownloadResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitQueryInfoResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitRefundResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitTodayTradeResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitWhiteAddResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitWhiteDeleteResponse;
use CMBUBank\UBank\Response\TransManager\TransManagerSubunitWhiteListResponse;

class UBankConstruct extends Builder
{

    public function __construct(array $config)
    {
        $this->gateway = $config['gateway'] ?? '';

        $this->userid = $config['userid'] ?? '';

        $this->bankPublicKey = $config['bankPublicKey'] ?? '';

        $this->privateKey = $config['privateKey'] ?? '';

        $this->sm4key = $config['sm4key'] ?? '';

        $this->logsDir = $config['logs_dir'] ?? '';

        $this->timeout = $config['timeout'] ?? '';
    }

    //----------------
    //----账户管理-----
    //----------------

    /**
     * 可经办业务模式查询(DCLISMOD)
     * @param string $busCode
     * @return AccountHandleBusinessInquiryResponse
     */
    public function accountHandleBusinessInquiry(string $busCode): AccountHandleBusinessInquiryResponse
    {
        $request = new AccountHandleBusinessInquiryRequest();
        $request->setBusCode($busCode);

        return $this->execute($request);
    }

    /**
     * 查询可经办的账户列表(DCLISACC)
     * @param string $busCode
     * @param string $busMode
     * @return AccountHandleAccountListResponse
     */
    public function accountHandleList(string $busCode, string $busMode): AccountHandleAccountListResponse
    {
        $request = new AccountHandleAccountListRequest();
        $request->setBusCode($busCode);
        $request->setBusMode($busMode);

        return $this->execute($request);
    }

    /**
     * 账户详细信息查询(NTQACINF)
     * @param string $backNo
     * @param string $account
     * @return AccountHandleAccountInfoResponse
     */
    public function accountInfo(string $backNo, string $account): AccountHandleAccountInfoResponse
    {
        $request = new AccountHandleAccountInfoRequest();
        $request->setBackNo($backNo);
        $request->setAccount($account);

        return $this->execute($request);
    }

    /**
     * 账户交易信息查询(DCTRSINF)
     * @param string $backNo
     * @param string $account
     * @param string $data
     * @param string $page
     * @return AccountTradeListQueryResponse
     */
    public function accountTradeListQuery(string $backNo, string $account, string $data, string $page): AccountTradeListQueryResponse
    {
        $request = new AccountTradeListQueryRequest();
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setData($data);
        $request->setPage($page);

        return $this->execute($request);
    }

    /**
     * 电子回单异步查询（ASYCALHD）
     * @param string $account
     * @param string $beginData
     * @param string $endData
     * @param array $extPageInfo
     * @return AccountPDFApplyResponse
     */
    public function accountPDFApply(string $account, string $beginData, string $endData, array $extPageInfo): AccountPDFApplyResponse
    {
        $request = new AccountPDFApplyRequest();

        $request->setAccount($account);
        $request->setBeginData($beginData);
        $request->setEndData($endData);
        $request->setExtPageInfo($extPageInfo);

        return $this->execute($request);
    }

    public function accountPDFDownload(string $taskId): AccountPDFDownloadResponse
    {
        $request = new AccountPDFDownloadRequest();

        $request->setTaskId($taskId);

        return $this->execute($request);
    }

    //----------------
    //----交易管家------
    //----------------
    //
    /**
     * 新增记账子单元(NTDMAADD)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param string $subName
     * @param string $backType 退票处理方式
     * @param string $overControl 额度控制标志
     * @param string $closeType 余额非零时是否可关闭
     * @return TransManagerCreateSubunitResponse
     */
    public function transManagerCreateSubunit(
        string $busMode,
        string $backNo,
        string $account,
        string $subCode,
        string $subName,
        string $backType = '',
        string $overControl = '',
        string $closeType = ''
    ): TransManagerCreateSubunitResponse
    {
        $request = new TransManagerCreateSubunitRequest();
        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubName($subName);
        $request->setBackType($backType);
        $request->setSubCode($subCode);
        $request->setOverControl($overControl);
        $request->setCloseType($closeType);
        $request->setReqCode('');

        return $this->execute($request);
    }

    /**
     * 关闭记账子单元(NTDUMDLT)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @return TransManagerCloseSubunitResponse
     */
    public function transManagerCloseSubunit(string $busMode, string $backNo, string $account, string $subCode): TransManagerCloseSubunitResponse
    {
        $request = new TransManagerCloseSubunitRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);

        return $this->execute($request);
    }

    /**
     * 记账子单元查询(NTDUMQRY)
     * @param string $backNo
     * @param string $account
     * @param string $beginSubCode
     * @param string $endSubCode
     * @param string $page
     * @return TransManagerSubunitListResponse
     */
    public function transManagerSubunitList(string $backNo, string $account, string $beginSubCode, string $endSubCode, string $page): TransManagerSubunitListResponse
    {
        $request = new TransManageSubunitListRequest();
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setBeginSubCode($beginSubCode);
        $request->setEndSubCode($endSubCode);
        $request->setPage($page);

        return $this->execute($request);
    }

    /**
     * 查询记账子单元付方白名单信息(NTDUMRLQ)
     * @param string $backNo
     * @param string $account
     * @param string $page
     * @return TransManagerSubunitWhiteListResponse
     */
    public function transManagerSubunitWhiteList(string $backNo, string $account, string $page): TransManagerSubunitWhiteListResponse
    {
        $request = new TransManagerSubunitWhiteListRequest();

        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setPage($page);

        return $this->execute($request);
    }

    /**
     * 设置记账子单元付方白名单信息(NTDUMRLA)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param string $whiteAccount
     * @return TransManagerSubunitWhiteAddResponse
     */
    public function transManagerSubunitWhiteAdd(string $busMode, string $backNo, string $account, string $subCode, string $whiteAccount): TransManagerSubunitWhiteAddResponse
    {
        $request = new TransManagerSubunitWhiteAddRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);
        $request->setWhiteAccount($whiteAccount);

        return $this->execute($request);
    }

    /**
     * 删除记账子单元付方白名单信息(NTDUMRLD)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param string $whiteAccount
     * @return TransManagerSubunitWhiteDeleteResponse
     */
    public function transManagerSubunitWhiteDelete(string $busMode, string $backNo, string $account, string $subCode, string $whiteAccount): TransManagerSubunitWhiteDeleteResponse
    {
        $request = new TransManagerSubunitWhiteDeleteRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);
        $request->setWhiteAccount($whiteAccount);

        return $this->execute($request);
    }

    /**
     * 设置记账子单元入账控制(NTDUMCTL)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @return TransManagerSubunitControlResponse
     */
    public function transManagerSubunitControl(string $busMode, string $backNo, string $account, string $subCode): TransManagerSubunitControlResponse
    {
        $request = new TransManagerSubunitControlRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);

        return $this->execute($request);
    }

    /**
     * 解除记账子单元入账控制(NTDUMCLE)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @return TransManagerSubunitDecontrolResponse
     */
    public function transManagerSubunitDecontrol(string $busMode, string $backNo, string $account, string $subCode): TransManagerSubunitDecontrolResponse
    {
        $request = new TransManagerSubunitDecontrolRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);

        return $this->execute($request);
    }


    /**
     * 记账子单元当天交易查询(NTDMTQRD)
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param string $page
     * @return TransManagerSubunitTodayTradeResponse
     */
    public function transManagerSubunitTodayTradeQuery(string $backNo, string $account, string $subCode, string $page): TransManagerSubunitTodayTradeResponse
    {
        $request = new TransManagerSubunitTodayTradeRequest();

        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);
        $request->setPage($page);

        return $this->execute($request);

    }

    /**
     * 记账子单元历史交易查询(NTDMTQRY)
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param string $beginData
     * @param string $endData
     * @param string $page
     * @return TransManagerSubunitHistoryTradeQueryResponse
     */
    public function transManagerSubunitHistoryTradeQuery(string $backNo, string $account, string $subCode, string $beginData, string $endData, string $page): TransManagerSubunitHistoryTradeQueryResponse
    {
        $request = new TransManagerSubunitHistoryTradeQueryRequest();

        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);
        $request->setBeginData($beginData);
        $request->setEndData($endData);
        $request->setPage($page);

        return $this->execute($request);
    }

    /**
     * 记账子单元交易明细对账单获取(NTDMTQRYPDF)
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param string $beginData
     * @param string $endData
     * @param string $page
     * @return TransManagerSubunitPDFCreateResponse
     */
    public function transManagerSubunitPDFCreate(string $backNo, string $account, string $subCode, string $beginData, string $endData, string $page): TransManagerSubunitPDFCreateResponse
    {
        $request = new TransManagerSubunitPDFCreateRequest();

        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);
        $request->setBeginData($beginData);
        $request->setEndData($endData);
        $request->setPage($page);

        return $this->execute($request);
    }

    /**
     * 记账子单元交易明细对账单处理结果查询请求(DCTASKID)
     * @param string $taskId
     * @return TransManagerSubunitPDFDownloadResponse
     */
    public function transManagerSubunitPDFDownload(string $taskId): TransManagerSubunitPDFDownloadResponse
    {
        $request = new TransManagerSubunitPDFDownloadRequest();

        $request->setTaskId($taskId);

        return $this->execute($request);
    }

    /**
     * 详情查询(NTDUMINF)
     * @param string $reqCode
     * @return TransManagerSubunitQueryInfoResponse
     */
    public function transManagerSubunitQueryInfo(string $reqCode): TransManagerSubunitQueryInfoResponse
    {
        $request = new TransManagerSubunitQueryInfoRequest();

        $request->setQueryCode($reqCode);

        return $this->execute($request);
    }


    /**
     * 记账子单元付款经办(NTOPRDMP)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param Payee $payee
     * @return TransManagerSubunitPaymentResponse
     */
    public function transManagerSubunitPayment(string $busMode, string $backNo, string $account, string $subCode, Payee $payee): TransManagerSubunitPaymentResponse
    {
        $request = new TransManagerSubunitPaymentRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);
        $request->setPayee($payee);

        return $this->execute($request);
    }

    /**
     * 记账子单元退款经办(NTOPRDMR)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $subCode
     * @param Payee $payee
     * @return TransManagerSubunitRefundResponse
     */
    public function transManagerSubunitRefund(string $busMode, string $backNo, string $account, string $subCode, Payee $payee): TransManagerSubunitRefundResponse
    {
        $request = new TransManagerSubunitRefundRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setSubCode($subCode);
        $request->setPayee($payee);

        return $this->execute($request);
    }

    /**
     * 记账子单元内部转账(NTDMITRX)
     * @param string $busMode
     * @param string $backNo
     * @param string $account
     * @param string $outSubCode
     * @param string $inSubCode
     * @param string $money
     * @param string $remark
     * @return TransManagerSubunitInterTransferResponse
     */
    public function transManagerSubunitInterTransfer(string $busMode, string $backNo, string $account, string $outSubCode, string $inSubCode, string $money, string $remark): TransManagerSubunitInterTransferResponse
    {
        $request = new TransManagerSubunitInterTransferRequest();

        $request->setBusMode($busMode);
        $request->setBackNo($backNo);
        $request->setAccount($account);
        $request->setOutSubCode($outSubCode);
        $request->setInSubCode($inSubCode);
        $request->setMoney($money);
        $request->setRemark($remark);


        return $this->execute($request);

    }
}